package com.zbj.feign.consumer;

import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * FeignService
 * https://blog.csdn.net/sun_shaoping/article/details/82079287
 * Spring Cloud Feign就是通过Fallback实现的，有两种方式：
 * 1、@FeignClient.fallback = UserFeignFallback.class指定一个实现Feign接口的实现类。
 * 2、@FeignClient.fallbackFactory = UserFeignFactory.class指定一个实现FallbackFactory<T>工厂接口类
 * 因为Fallback是通过Hystrix实现的，所以需要开启Hystrix，spring boot application.properties/***.yml
 * 文件配置feign.hystrix.enabled=true，这样就开启了Fallback
 *
 * @author weigang
 * @create 2019-08-06
 **/
@FeignClient(value = "feign-provider", fallback = FeignFallBack.class)
// 加上前缀路径后 FeignConsumer不能调用FeignProvider
//@RequestMapping("/feign")
public interface FeignService {

    /**
     * 服务中方法的映射路径
     *
     * @return
     */
    @RequestMapping(value = "/hello", method = RequestMethod.GET)
    String hello();

    @RequestMapping(value = "/hello1", method = RequestMethod.GET)
    String hello(@RequestParam String name);

    /**
     * @param name
     * @param age
     * @return
     * @RequestHeader 入参注解与FeignProvider保持一致
     */
    @RequestMapping(value = "/hello2", method = RequestMethod.GET)
    User hello(@RequestHeader("name") String name, @RequestHeader("age") Integer age);
    // 采用下面方法定义启动抛出异常 详见 feign-consumer README.md
    //User hello(String name, Integer age);

    @RequestMapping(value = "/hello3", method = RequestMethod.POST)
    String hello(@RequestBody User user);
}
